# -*- coding: utf-8 -*-

from django.db import models
from django.utils.translation import ugettext_lazy as _


class Dialog(models.Model):
    title = models.CharField(_(u'Title'), max_length=50,
        help_text=_(u'Used for the title attribute of the dialog.'))
    ident = models.SlugField(_(u'Identifier'),
        help_text=_(u'Dialog for the same topic in another language must '
                    u'define exactly the same identifier.'))
    lang = models.CharField(_(u'Language'), max_length=5,
        help_text=_(u'Lookup is done via istartswith.'))
    width = models.PositiveIntegerField(_(u'Dialog width'), default=500,
        help_text=_(u'Width of the dialog.'))
    opener_class = models.CharField(_(u'Opener class'), max_length=15,
        default=u'.opener', help_text=_(u'CSS class of the element which '
            u'gets the click event to open the dialog (jQuery notation).')
    )
    text = models.TextField(_(u'Text'), help_text=_(u'Main content. You '
        u'can use HTML here.'))

    def __unicode__(self):
        return u'[{0}] {1} ({2})'.format(self.lang, self.title, self.ident)

    def save(self, *args, **kwargs):
        self.lang = self.lang.lower()
        super(InternalHelp, self).save(*args, **kwargs)

    class Meta:
        verbose_name = _(u'Dialog')
        verbose_name_plural = _(u'Dialogs')
        ordering = ['ident', 'lang']
